#ifndef SCOREENTRY_H
#define SCOREENTRY_H

#include <QWidget>
#include <QDate>
#include <QDateEdit>
#include <QComboBox>
#include <QPushButton>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGroupBox>
#include <QRadioButton>
#include <QCheckBox>
#include <QLabel>
#include <QScrollArea>
#include <QMap>
#include <QList>
#include <QMessageBox>
#include <QEvent>

class MainWindow;
class Database;

class ScoreEntry : public QWidget
{
    Q_OBJECT

public:
    explicit ScoreEntry(MainWindow *parent = nullptr);
    ~ScoreEntry();

    void refreshData();

private slots:
    void onUnitChanged(const QString &unit);
    void onDateChanged(const QDate &date);
    void saveScores();
    // 鼠标悬浮事件槽函数
    void onRoomGroupEntered();
    void onRoomGroupLeft();
    // 差评分选择变化时的处理函数
    void onPoorScoreToggled(bool checked);
    // 检查并确保至少选择了一种问题类型
    void validatePoorScoreIssues();

private:
    MainWindow *mainWindow;
    Database *database;

    QDateEdit *dateEdit;
    QComboBox *unitSelect;
    QPushButton *saveButton;
    QScrollArea *scrollArea;
    QWidget *scrollContent;
    QVBoxLayout *roomsLayout;

    QDate currentDate;
    QString currentUnit;

    // 用于存储UI组件的结构
    struct RoomScoreControls
    {
        QGroupBox *roomGroup; // 添加房间组引用
        QLabel *roomLabel;
        QRadioButton *excellentRadio;
        QRadioButton *goodRadio;
        QRadioButton *poorRadio;
        QCheckBox *fireCheck;
        QCheckBox *smokingCheck;
        QCheckBox *sanitaryCheck;
        QCheckBox *safetyCheck;
    };

    QMap<QString, RoomScoreControls> roomControls;
    QString lastHighlightedRoom; // 记录上次高亮的房间
    QString currentCheckingRoom; // 当前正在检查问题类型的房间

    void setupUi();
    void loadRooms();
    void loadScoreData();
    bool confirmOverwrite();
    bool eventFilter(QObject *watched, QEvent *event) override; // 事件过滤器
};

#endif // SCOREENTRY_H